# _*_coding:utf-8_*_
# Author   :luoyuan 
# Date     :2018/12/9 10:28  
import requests
from bs4 import BeautifulSoup

# 获取网页数据
response = requests.get(
    url='http://www.27270.com/'
)
# 设置编码格式
response.encoding = response.apparent_encoding

# 处理成文本数据
soup = BeautifulSoup(response.text, features='html.parser')
target = soup.find(id='auto-header')
li_list = target.find_all('li')

for i in li_list:
    a = i.find('a')
    if a:
         print(a.attrs.get('href'))
         txt = a.find('h3').text  # 拿到文本类型
         print(txt)
         img_url = a.find('img').attrs.get('src')
         # 拿到图片
         img_response = requests.get(url=img_url)
         import uuid
         file_name = str(uuid.uuid4()) + '.jpg'
         with  open(file_name, 'wb') as f:
             f.write(img_response.content)

